package com.pactera.madp.cp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.cp.api.dto.moments.MomentsPageDTO;
import com.pactera.madp.cp.api.vo.moments.MomentsPageVO;
import com.pactera.madp.cp.service.CpMomentsTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 朋友圈任务审批控制层
 *
 * @author huhao
 * @since 2022-06-14 9:15:47
 */
@RestController
@RequestMapping("/moments-task-approval")
@Api(value = "moments-task-approval", tags = "朋友圈任务管理")
@AllArgsConstructor
@Slf4j
public class CpMomentsTaskApprovalController {

    private CpMomentsTaskService cpMomentsTaskService;

    @GetMapping("/page")
    @ApiOperation("朋友圈任务审核分页")
    public R<Page<MomentsPageVO>> getMomentsPage(MomentsPageDTO dto, Page page) {
        return R.ok(cpMomentsTaskService.getMomentApprovalPage(dto, page));
    }

    @PutMapping("/approval")
    @ApiOperation("审批朋友圈任务")
    public R approval(@RequestParam("id") Integer id, String  opinion, Integer state) {
        if (state != 1 && state != 2) {
            return R.failed("审批状态不在可操作范围[1-拒绝、2-同意]内");
        }
        return cpMomentsTaskService.approval(id, opinion, state) ? R.ok() : R.failed();
    }

}

